package com.yylending.las.authority.gestures;

import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yylending.las.Global;
import com.yylending.las.YJKD;
import com.yylending.las.common.utils.preferenceutils.PreferenceConstants;

/**
 * Created by HenryZhang on 2016/11/21.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public class GesturesPresenter extends Presenter<Model, GesturesPresenter.View> {
	private final static String TAG = "GesturesPresenter";

	public interface View extends IView {
	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
	}

	@Override
	public void detach() {
		mView = null;
	}

	public static boolean readStatus() {
		return YJKD.getInstance().getPreferenceManager().isEnablePatternLock();
	}

	public static void writeStatus(boolean isChecked) {
		YJKD.getInstance().getPreferenceManager().savePreference(PreferenceConstants.SP_KEY_GESTURES_TOGGLE, isChecked);
	}

	public static String readGestures() {
		return YJKD.getInstance().getPreferenceManager().getPatternLock();
	}

	public static void writeGestures(String passwrod) {
		YJKD.getInstance().getPreferenceManager().savePreference(PreferenceConstants.SP_KEY_GESTURES_STRING, passwrod);
	}

	public static void resetGestureCount() {
		YJKD.getInstance().getPreferenceManager().savePreference(PreferenceConstants.SP_KEY_GESTURES_COUNT, 0);
	}

	public static int getGestureCount() {
		return YJKD.getInstance().getPreferenceManager().getUnlockFailedTimes();
	}

	public static void setGestureCount(int count) {
		YJKD.getInstance().getPreferenceManager().savePreference(PreferenceConstants.SP_KEY_GESTURES_COUNT, count);
	}

	public static int getGestureRemainCount() {
		return Global.GESTURE_MAX_COUNT - YJKD.getInstance().getPreferenceManager().getUnlockFailedTimes();
	}
}
